package zj.com.activities;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.zfdang.multiple_images_selector.SelectorSettings;

import org.w3c.dom.Text;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import zj.com.adapter.LookImgGridAdapter;
import zj.com.adapter.UploadImgGridAdapter;
import zj.com.model.JcxDB;
import zj.com.zj.R;

/**
 * Created by xi on 16/6/9.
 * 待确认检查项详情
 */
public class DqrJcxDetailActivity extends  BaseActivity implements View.OnClickListener {

    public ImageView left_iv;
    public TextView title_name,right_tv;

    public GridView uploadGridView;
    public List<String> list;
    public LookImgGridAdapter adapter;

    public EditText desc_tv;
    public TextView yh_tv;
    public TextView total_tv,fen_tv;
    public TextView content_tv;




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dqr_jcx_detail);
        initView();
    }

    public void initView(){
        left_iv = (ImageView) findViewById(R.id.left_iv);
        left_iv.setVisibility(View.VISIBLE);
        left_iv.setOnClickListener(this);
        title_name = (TextView) findViewById(R.id.title_name);
        title_name.setText("检查任务详情");
        right_tv = (TextView) findViewById(R.id.right_tv);
        right_tv.setText("保存");
        right_tv.setVisibility(View.GONE);


        desc_tv = (EditText) findViewById(R.id.desc_et);
        yh_tv = (TextView) findViewById(R.id.yh_tv);
        total_tv = (TextView) findViewById(R.id.total_tv);
        content_tv = (TextView) findViewById(R.id.content_tv);
        fen_tv= (TextView) findViewById(R.id.fen_tv);
        desc_tv.setEnabled(false);
        uploadGridView = (GridView) findViewById(R.id.uploadGridView);

        list = new ArrayList<>();
        adapter = new LookImgGridAdapter(list,this);
        uploadGridView.setAdapter(adapter);

        uploadGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                Intent intent = new Intent(DqrJcxDetailActivity.this,LookImgActivity.class);
                intent.putExtra("imgs",(Serializable)list);
                intent.putExtra("position",position);
                startActivity(intent);
            }
        });

       JcxDB jcx = (JcxDB) getIntent().getSerializableExtra("detail");
        if(jcx != null){


            yh_tv.setText("隐患级别:"+jcx.getRiskName());
            total_tv.setText("总分:"+jcx.getTotalPoints());
            fen_tv.setText("扣分:" + jcx.getPoints());
            content_tv.setText("检查内容:"+jcx.getInspectContentName());
            desc_tv.setText(jcx.getRiskDes());

            String img = jcx.getImgs();
            if(img != null){
              String[] imgs =   img.split(",");
               list.clear();
              for(int i=0;i<imgs.length;i++){
                  String url  = imgs[i];
                  list.add(url);
              }
                adapter.setDataChange(list);
            }
        }
    }



    @Override
    public void onClick(View v) {

        switch (v.getId()){
            case R.id.left_iv:
                finish();
                break;
        }
    }
}
